#ifndef GLOG_NO_ABBREVIATED_SEVERITIES
#define GLOG_NO_ABBREVIATED_SEVERITIES // 如果不加这个宏定义代码就会报错
#endif

#include <QApplication>
#include <QDebug>
#include <QDir>
#include "MainWidget.h"
#include "glog/logging.h"

using namespace google;

int main(int argc, char *argv[])
{
    const char *log_dir_path = "./log";//日志文件目录
    const char *log_file_prefix = "./log/log_";//日志文件前缀

    QApplication a(argc, argv);

    //检查日志目录是否存在，若不存在则创建
    if (!QDir().exists(log_dir_path))
    {
        if (QDir().mkpath(log_dir_path))
        {
            qDebug() << "directory created successfully";
        }
        else
        {
            qDebug() << "failed to create directory";
        }
    }

    FLAGS_max_log_size = 10;//日志文件最大大小（MB）
    FLAGS_stop_logging_if_full_disk = true;//磁盘满时停止写入
    FLAGS_logtostderr = false;//禁用控制台输出
    google::InitGoogleLogging(argv[0]);
    google::SetLogDestination(google::GLOG_INFO, log_file_prefix);
    google::SetLogDestination(google::GLOG_WARNING, log_file_prefix);
    google::SetLogDestination(google::GLOG_ERROR, log_file_prefix);
    google::SetLogDestination(google::GLOG_FATAL, log_file_prefix);
    google::SetLogFilenameExtension(".txt");//设置扩展名为 .txt

    LOG(INFO) << "student info manager system init success!";
    LOG(WARNING) << "warning info test";
    LOG(ERROR) << "error info test";

    MainWidget mWidget;
    mWidget.show();

    a.exec();

    //关闭glog
    google::ShutdownGoogleLogging();

    return 0;
}
